{extend name="base/base" /}

{block name="content"}
        <form class="layui-form" id="edit_form" onsubmit="return false">
          <div class="layui-form-item">
            <label class="layui-form-label">轮播图：</label>
            <div class="layui-input-inline">
                <img src="" style="width: 100px;height: 100px" id="show_upload_img">
                <input type="hidden" name="pic" id='pic' value="">
             </div>
          </div>
          <div class="layui-form-item">
            <div class="layui-input-block">
              <button type="button" class="layui-btn" id="upload">
                <i class="layui-icon"></i>上传图片
              </button>
            </div>
          </div>
          <div class="layui-form-item">
            <div class="layui-input-block">
              <button class="layui-btn" lay-filter="formDemo" onclick="ajax()">立即提交</button>
              <button onclick="cancel()" class="layui-btn layui-btn-primary">取消</button>
            </div>
          </div>
        </form>
{/block}
{block name="script"}
<script>
  layui.use('upload', function(){
    var upload = layui.upload;
    upload.render({
    elem: '#upload'
    ,url: '{:C("system_url")}/api/Upload/upload_img'
    ,before:function(){
      var index = layer.msg('正在拼命处理...' , {
        icon: 16 ,
        shade: 0.6 ,
        time: 0 ,
      });
    }
    ,done: function(res){
      if(res.code==0){
        $("#show_upload_img").attr('src',res.data);
         $("#pic").val(res.data);
        layer.msg('上传图片成功');
      } else {
        layer.msg('上传图片失败');
      }
    }
    });      
  });
function ajax(){
  var post_data = $("#edit_form").serialize();
  $.ajax({
      url:"",
      type:"POST",
      data:post_data,
      success:function(ret){
          if (ret.code == 0) {
            layer.msg('添加成功');
            window.location.href=document.referrer;
          }
          if (ret.code == 1) {
              layer.msg(ret.msg);
          }
      }
  });
}
function cancel(){
    window.location.href=document.referrer;
}
</script>
{/block}
